CXX := g++

LINKER := ld

BUILDDIR := build

SRCDIR := src

LIBS := -lpthread

OBJECTS := org/antban/ptr/ref.o org/antban/thread/thread.o

COMPILE_OBJECTS := $(addprefix $(BUILDDIR)/, $(OBJECTS))

test: mkdirs $(OBJECTS) main.o
	$(CXX) $(LIBS) $(COMPILE_OBJECTS) build/main.o -o $@

sthlib.a: mkdirs $(OBJECTS)
	ar cq $@ $(COMPILE_OBJECTS)

sthlib.so: mkdirs $(OBJECTS)
	$(CXX) -shared $(LIBS) $(COMPILE_OBJECTS) -o $@

all: clean sthlib.a sthlib.so test
	

.PHONY : clean sthlib.a sthlib.so test $(OBJECTS)

clean:
	rm -rf build sthlib.* test
 
main.o: $(SRCDIR)/main.cpp
	$(CXX) -c $(SRCDIR)/main.cpp -o $(BUILDDIR)/main.o

org/antban/ptr/ref.o: $(SRCDIR)/org/antban/ptr/ref.cpp $(SRCDIR)/org/antban/ptr/ref.h
	$(CXX) -c $(SRCDIR)/org/antban/ptr/ref.cpp -o $(BUILDDIR)/org/antban/ptr/ref.o

org/antban/thread/thread.o: $(SRCDIR)/org/antban/thread/thread.cpp $(SRCDIR)/org/antban/thread/thread.h $(SRCDIR)/org/antban/thread/runnable.h
	$(CXX) -c $(SRCDIR)/org/antban/thread/thread.cpp -o $(BUILDDIR)/org/antban/thread/thread.o

mkdirs:
	mkdir -p $(BUILDDIR)/org/antban/ptr $(BUILDDIR)/org/antban/thread 
